package com.dynamic.lesscss.engine;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.internal.PluginAction;

@SuppressWarnings("restriction")
public class LessFolderAction extends AbstractAction implements IObjectActionDelegate{

	private ISelection selection=null;
	@Override
	public void run(IAction action) {
		if (action instanceof PluginAction) {
			PluginAction opAction = (PluginAction) action;
			ISelection selection = opAction.getSelection();
			if (selection instanceof TreeSelection) {
				Object element = ((TreeSelection) selection)
						.getFirstElement();
				if (element instanceof IResource) {
					IResource resouce = (IResource) element;
					compileFolder(resouce);
					try {
						resouce.getParent().refreshLocal(IResource.DEPTH_INFINITE,null);
					} catch (CoreException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	@Override
	public void selectionChanged(IAction arg0, ISelection selection) {
		// TODO Auto-generated method stub
		this.selection=selection;
	}

	@Override
	public void setActivePart(IAction arg0, IWorkbenchPart arg1) {
		// TODO Auto-generated method stub
		
	}

}
